/*
 * Copyright (c) 2020 - present, Inspur Genersoft Co., Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.inspur.edp.formserver.vmapi.dto;

import io.iec.edp.caf.securityentry.api.data.SecurityEntry;
import io.iec.edp.caf.securityentry.api.data.SecurityEntry4RuleDTO;
import lombok.Getter;
import lombok.Setter;

import java.util.HashMap;
import java.util.Map;

/**
 * 视图模型权限信息DTO
 * @author sunhongfei01
 * @since 2025-02-26
 */
@Getter
@Setter
public class ViewModelAuthInfoDto {
    // 功能权限
    private SecurityEntry funcSecurity;
    // 数据权限, key为节点编码路径
    private Map<String, ViewModelAuthSecurityDto> authSecurityMap = new HashMap<>();
    // 列权限, key为节点编码路径
    private SecurityEntry columnSecurity;

    /**
     * 添加数据权限
     * @param code 数据权限归属的节点编码
     * @param securityEntry 数据权限
     * @param entry4RuleDTO 规则权限
     */
    public void addAuthSecurityEntry(String code, SecurityEntry securityEntry, SecurityEntry4RuleDTO entry4RuleDTO) {
        // 如果数据权限和规则权限都为空，则不添加
        if (securityEntry == null && entry4RuleDTO == null) {
            return;
        }
        authSecurityMap.put(code, new ViewModelAuthSecurityDto(securityEntry, entry4RuleDTO));
    }
}
